<template>
  <div style="padding: 20px">
    <div class="headerBoxList">
      <svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 13L34 34L23 44V4L34 14L12 35" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>
      <span style="margin-left: 10px">蓝牙信息</span>
    </div>
    <div class="contentBoxYY" style="">
      <el-collapse v-model="activeName" accordion>
        <el-collapse-item v-for="(item,index) in listData" :key="index" :title="'🚩 '+ item.titleKey+` （${item.content.length}行）`" :name="index">
            <div style="background: #282828;color: rgb(101, 177, 235);padding-left:20px;" v-for="(data,j) in item.content" :key="j">
                {{ data }}
            </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>

<script>
  import { getRxTmpPathApi } from '@/api/phoneInfo/index'
export default {
  name: "proofBaseList",
  data() {
    return {
      activeName: 0,
      listData:[]
    };
  },
  mounted(){
  },
  created() {
    this.initFunction();
  },
  methods: {
    initFunction() {

let node = this.$route.params.nodeData.data;
      let dataJson = {
        "proof_num":node.proof_num,
        "rxTmpPath":'/'+node.subtype
      }
      getRxTmpPathApi(dataJson).then(res=>{
        const stringData = res.data;
        
      const delimiters = [
        "Bluetooth Status",
        "Enable log",
        "BluetoothManagerService",
        "AdapterProperties",
        "AdapterState:",
        "btservice-BluetoothAdapterProperties",
        "btservice-BluetoothAdapterState:",
        "Metadata",
        "GATT Scanner Map",
        "com.gotokeep.keep",
        "android.uid.bluetooth:1002 (Registered)",
        "Device Volume Memory Map",
        "Bluetooth Config",
      ];

      const dataArray = [];
      let currentData = "";

      for (let i = 0; i < delimiters.length; i++) {
        const delimiter = delimiters[i];
        const startIndex = stringData.indexOf(delimiter);
        const endIndex =i < delimiters.length - 1? stringData.indexOf(delimiters[i + 1]): stringData.length;

        if (startIndex !== -1 && endIndex !== -1) {
          const data = stringData.slice(startIndex, endIndex).trim();
          dataArray.push(data);
        }
      }
      let arr = [];
      // 格式化字符串数组为json数据
      for (let index = 0; index < dataArray.length; index++) {
        const element = dataArray[index];
        const originalString = element;
        const delimiter = "\n";

        const delimiterIndex = originalString.indexOf(delimiter);

        if (delimiterIndex !== -1) {
          const firstPart = originalString.substring(0, delimiterIndex).trim();
          const secondPart = originalString
            .substring(delimiterIndex + 1)
            .trim();
          let item = {
            titleKey: firstPart,
            content: secondPart.split("\n"),
          };
          arr.push(item);
        } else {
          console.log("Delimiter not found in the string.");
        }

        // arr.push(item)
      }
      this.listData = arr;
      })


    },
  },
};
</script>

<style scoped>
.headerBoxList {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #d2d2d2;
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
}
.contentBoxYY{
    width: 95%; 
    margin: 0 auto;
    overflow: hidden;
    height:95vh;
    overflow-y: auto;
}
@media screen and (min-width: 2360px) {
    .contentBoxYY{
        width: 95%; 
        margin: 0 auto;
        overflow: hidden;
        height:67vh;
        overflow-y: auto;
    }
}

</style>